/*
 *  Copyright 2010 netjois.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package edu.upf.userinterface.impl;

import edu.upf.content.DescriptionContent;
import edu.upf.content.ImageObject;
import edu.upf.content.Video;
import edu.upf.utils.Definitions;
import java.awt.Image;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author netjois
 */
public class LibraryTableModel extends AbstractTableModel implements Definitions {

    private List<DescriptionContent> datalist = new ArrayList();
    private String[] columns = {"Name", "Type", "Size", "Popularity","Thumbnail"};

    @Override
    public int getRowCount() {
        return datalist.size();
    }

    @Override
    public int getColumnCount() {
        return columns.length;
    }

    @Override
    public String getColumnName(int col) {
        return columns[col];
    }

    public void addDescriptionContent(DescriptionContent dc) {
        datalist.add(dc);
        fireTableDataChanged();
    }

    public DescriptionContent getDescriptionContentAt(int row) {
        return (DescriptionContent) datalist.get(row);
    }

    public DescriptionContent removeDescriptionContentAt(int row) {
        DescriptionContent dc = (DescriptionContent) datalist.remove(row);
        fireTableDataChanged();
        return dc;
    }

    @Override
    public Class getColumnClass(int column){
        if(column==LIBRARY_THUMB_COLUM){
            return Image.class;
        }else{
            return Object.class;
        }
    }

    @Override
    public Object getValueAt(int row, int col) {
        DescriptionContent descriptionContent = (DescriptionContent) datalist.get(row);
        switch (col) {
            case 0:
                return descriptionContent.getName();
            case 1:
                if(descriptionContent instanceof ImageObject){
                    return IMAGE;
                }else if(descriptionContent instanceof Video){
                    return VIDEO;
                }
                return "unkown";
            case 2:
                return descriptionContent.getSize();
            case 3:
                return descriptionContent.getPopularity();
            case 4:
                return descriptionContent.getThumbnail();
            default:
                return null;
        }
    }
}
